import { createRouter, createWebHistory } from 'vue-router'
import LayoutView from '@/views/Layout/myIndex.vue'
import loginView from '@/views/Login/myIndex.vue'
import homeView from '@/views/Home/myIndex.vue'
import categoryView from '@/views/Category/myIndex.vue'
import subCategoryView from '@/views/subCategory/myIndex.vue'
import detailView from '@/views/Detail/myIndex.vue'
import cartListView from '@/views/CartList/myIndex.vue'
import Cheakout from '@/views/Checkout/myIndex.vue'
import payView from '@/views/Pay/myIndex.vue'
import PayBackView from '@/views/Pay/PayBack.vue'
import MemberView from '@/views/Member/myIndex.vue'
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/', component: LayoutView,
      children: [
        { path: '', component: homeView },
        { path: 'category/:id', component: categoryView },
        { path: 'category/sub/:id', component: subCategoryView },
        { path: 'detail/:id', component: detailView },
        { path: 'cartlist', component: cartListView },
        { path: 'checkout', component: Cheakout },
        { path: 'pay', component: payView },
        { path: 'paycallback', component: PayBackView },
        {
          path: 'member',
          component: MemberView,
          children: [
            { path: '', component: UserInfo },
            { path: 'order', component: UserOrder }
          ]
        }
      ]
    },
    {
      path: '/login', component: loginView
    },
  ],
  // 路由滚动行为,切换页面是滚动条回到页面顶部
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
